<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<!-- Preview tooltip -->
<div class="ttip-ad-preview" id="tooltip">
    <p class="myclear">
		<img alt="" class="ttip-ad-preview-arrow" src="/images/toannhtooltiparrow.gif" />
	</p>
	<div class="ttip-ad-preview-inner">
		<div class="ttip-ad-preview-inner-pad" id="content">
            <div style="width: 496px;height:273px;text-align: center;">
				<img src="images/ajax-loader.gif" style="margin-top: 80px;"/>
            </div>
		</div>
		<p class="ttip-adprv-btn-box myclear">
            <a class="btn" id="copyad-tooltip">
                <span>
				    <?php echo $archive_lang['restoreAd'];?>
                </span>
			</a>
            
			<a onclick="tooltip_preview_remove1()" class="ttip-adprv-cancel marleft10">
				<?php echo $archive_lang['cancelTooltip'];?>
			</a>
            
		</p>
	</div>
</div>
<!-- colum right -->
<div class="middle myclear">
		<div class="pad10">
            <table width="100%" class="marbottom10 martop20"  border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="50%">
                        <h2>
                			<?php echo $archive_lang['archive']?>
                		</h2>
					</td>
				</tr>
			</table>
            <div class="dashboard-box myclear">
				<table class="mbd-timebox martop20" cellpadding="0" cellspacing="0" border="0">	
					<tr>
						<td class="padright10 ver-middle">
							<input class="input-time" type="text" readonly="readonly" id="date" value="<?php echo date('d/m/Y',strtotime($fromdate))?> <?php echo $archive_lang['to'];?> <?php echo date('d/m/Y',strtotime($todate))?>" />
						</td>

                        <td class="ver-middle">
                            <img id="loading" src="/images/ajaxLoading.gif" style="display: none;"/>
                        </td>
					</tr>
				</table>
				<div id="campaigndiv">
    				<table class="tbl-list" width="100%" cellpadding="0" cellspacing="0" border="1" id="table">
                    <thead>
    					<tr>
    						<th class="td-label bold text-center ver-middle" width="25" style="padding: 5px 0;">
    							<span><?php echo $archive_lang['#'];?></span>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="50" style="padding: 5px 0;">
    							<span><?php echo $archive_lang['preview'];?></span>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="155" style="padding: 5px 0;">
                                <p class="ver-middle" style="height:33px;line-height: 33px;"><?php echo $archive_lang['ad'];?></p>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="43" style="padding: 5px 0;">
    							<span><?php echo $archive_lang['status'];?></span>
    						</th>
                            
                            <th class="td-label bold text-center ver-middle" width="64" style="padding: 5px 0;">
    							Vùng miền								
							</th>
    						
    						<th class="td-label bold text-center ver-middle" width="49" style="padding: 5px 0;">
    							<p class="ver-middle" style="height:33px;line-height: 33px;">Click</p>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="76" style="padding: 5px 0;">
    							<p class="ver-middle" style="height:33px;line-height: 33px;"><?php echo $archive_lang['impressions'];?></p>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="70" style="padding: 5px 0;">
    							<p class="ver-middle" style="height:33px;line-height: 33px;"><?php echo $archive_lang['uv'];?></p>
    						</th>
    						
    						<th class="td-label bold text-center ver-middle" width="40" style="padding: 5px 0;">
    							<p class="ver-middle" style="height:33px;line-height: 33px;">CTR %</p>
    						</th>
    					</tr>
                    </thead>
                    <tbody>
    					<?php $index=1+($page-1)*$numrow;
                        foreach($info as $if)
                        {
                        ?>
    					<tr>
    						<td class="ver-middle">
    							<p class="db-list-cl-stt">
    								<?php echo $index;?>
    							</p>
    						</td>
    						
    						<td class="ver-middle">
                                
    							<p class="db-list-cl-img">
                                    <a onclick="ajax_tooltip(<?php echo $if['bannerid']?>,this,<?php echo $index;?>,<?php echo $if['status'];?>);">
          						        <img alt="" src="<?php echo $if['filepath'];?>" width="40" height="40"/>
                                    </a>
    							</p>
    						</td>
    						
    						<td class="ver-middle">
    							<div class="db-list-cl-banner">
    								<p >
                                        <a href="<?php echo site_url('bannerdetail/index?bannerid='.$if['bannerid'].'&fromdate='.$fromdate.'&todate='.$todate)?>">
    									   <?php echo $if['bannername'];?>
                                        </a>
    								</p>
    								<p class="text-999">
                                        <a href="<?php echo site_url('campaigndetail/index?campaignid='.$if['campaignid'].'&fromdate='.$fromdate.'&todate='.$todate)?>">
    									   <?php echo $if['campaignname'];?>
                                        </a>
    								</p>
    							</div>
    						</td>
    						
    						<td class="ver-middle">
    							<p class="db-list-cl-status edit3 text-center">
                                    <input type="hidden" value="<?php echo site_url('banner/edit') . '?bannerid='. $if['bannerid'].'&type=1';?>" class="hddEditLink"/>
                                    <?php //echo $if['status'];
                                    if($if['outofstore']==1)
                                        echo '<img class="cursor-pointer" alt="" src="images/dealed.png" title="'.$archive_lang['dealed'].'"/>';
                                    elseif($if['status']==-1)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgok.gif" title="'.$archive_lang['completed'].'"/>';
                                    elseif($if['status']==0)
                                        echo '<img class="cursor-pointer" alt="" src="images/temp_deleted.gif" title="'.$archive_lang['temp_deleted'].'"/>';
                                    elseif($if['status']==1)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgrun.gif" title="'.$archive_lang['running'].'"/>';
                                    elseif($if['status']==2)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgpause.gif" title="'.$archive_lang['paused'].'"/>';
                                    elseif($if['status']==3)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgwait.png" title="'.$archive_lang['waiting'].'"/>';
                                    elseif($if['status']==4)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgproblem.png" title="'.$archive_lang['problem'].'"/>';
                                    elseif($if['status']==5)
                                        echo '<img class="cursor-pointer" alt="" src="images/imgout-of-money.png" title="'.$archive_lang['outofmoney'].'"/>';
                                    elseif($if['status']==6)
                                        echo '<img class="cursor-pointer" alt="" src="images/het_ngan_sach.gif" title="'.$archive_lang['het_ngan_sach'].'"/>';
                                    elseif($if['status']==8)
                                        echo '<img class="cursor-pointer" alt="" src="images/chochay.gif" title="'.$archive_lang['waittorun'].'"/>';
                                    else
                                        echo $if['status'];
                                    ?>
    							</p>
    						</td>
                            
                            <td class="ver-middle">
								<p class="pad5">
									<?php $mystring =$if['locationAd'];
                                    if(strpos($mystring,'0')!==false) {
                                         $mystring = str_replace("0","Toàn quốc",$mystring);
                                    }
                                    if(strpos($mystring,'1')!==false) {
                                         $mystring = str_replace("1","Bắc",$mystring);
                                    }
                                    if(strpos($mystring,'2')!==false) {
                                         $mystring = str_replace("2","Trung",$mystring);
                                    }
                                    if(strpos($mystring,'3')!==false) {
                                         $mystring = str_replace("3","Nam",$mystring);
                                    }
                                    echo rtrim($mystring,',');
                                     ?>
								</p>	
							</td>
    						
    						<td class="ver-middle">
    							<div class="db-list-cl-click">
    								<p>
                                        <?php if(($if['clicks']!= 'N/A')&&($if['clicks']!= 0)) { ?>
        									<a><?php echo $if['clicks'];?></a>
        								<?php }else{ ?>
        								    <?php echo $if['clicks'];?>
        								<?php }?>
                                    </p>
    							</div>
    						</td>
    						
    						<td class="ver-middle">
    							<div class="db-list-cl-imp">
    								<p>
                                        <?php if(($if['impressions']!= 'N/A')&&($if['impressions']!= 0)) { ?>
        									<a><?php echo $if['impressions'];?></a>
        								<?php }else{ ?>
        								    <?php echo $if['impressions'];?>
        								<?php }?>
    								</p>
    							</div>
    						</td>
    						
    						<td class="ver-middle">
    							<div class="db-list-cl-uv">
    								<p>
    									<?php echo $if['uviews']==0 ? 'N/A' : $if['uviews'];?>
    								</p>
    							</div>
    						</td>
    						
    						<td class="ver-middle">
    							<div class="db-list-cl-ctr">
    								<p>
    									<?php echo $if['CTR'];?>
    								</p>
    							</div>
                                <input type="hidden" class="abcdef" value="<?php echo $if['bannerid']; ?>" />
    						</td>
    					</tr>
    					<?php
                        $index++;
                        }
                        ?>
                    </tbody>
    				</table>
                    <div id="pager" style="font-family: tahoma;border: solid 1px #D6D6D6;float: right; margin-top: 10px;background-color: white;padding:3px 10px 4px;">
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td class="ver-middle">
                                    <span class="ver-middle"><?php echo $archive_lang['page'];?></span>
                                    <input readonly="readonly" type="text" id="pagedisplay" class="pagedisplay ver-middle" size="2" style="border:0;" value="<?php echo $page.'/'.$totalpage;?>"/>
                                </td>
                                <td class="ver-middle" style="padding-bottom: 2px;">
                                    <img src="/images/imgpre.gif" class="prev ver-middle" id="prev" <?php echo ($page>1)? 'onclick="prev_page();"':'';?>/>
                                    <img src="/images/imgnext.gif" class="next ver-middle" id="next" <?php echo ($page<$totalpage)? 'onclick="next_page();"':'';?>/>
                                </td>
                                <td style="padding-top: 2px;">
                                    <select class="pagesize ver-middle" style="border: 0;background: #fff;" id="pagesize" onchange="pagesize1()">
                            			<option value="10" <?php echo ($numrow==10) ? 'selected="selected"':'' ;?>>10</option>
                            			<option value="20" <?php echo ($numrow==20) ? 'selected="selected"':'' ;?>>20</option>
                            			<option value="30" <?php echo ($numrow==30) ? 'selected="selected"':'' ;?>>30</option>
                            			<option value="40" <?php echo ($numrow==40) ? 'selected="selected"':'' ;?>>40</option>
                            		</select>
                                </td>
                            </tr>
                        </table>       
                        </div>
    				</div>	
    			</div>
			<br /><br /><br /><br /><br />
			<p class="text-right pad10">
				<img id="top" class="cursor-pointer" alt="" src="images/backtotop.gif" onclick="window.scrollTo(0,0); return false;"/>
			</p>
			
		</div> <!-- end colum right -->
		<!-- important. fix for ie 6. Don't remove -->
		<!--[if IE 6]><br class="clearboth" /><![endif]-->
    </div>
<script type="text/javascript">
    function pagesize1()
    {
        var numrow = $('#pagesize').val();
        var temp = $('#date').val();
        temp=temp.split(' <?php echo $archive_lang['to']?> ');
     	var fromdate=temp[0];
     	var todate=temp[1];
     	fromdate=fromdate.split('/');
        fromdate=fromdate[2]+'-'+fromdate[1]+'-'+fromdate[0];
        todate=todate.split('/');
        todate=todate[2]+'-'+todate[1]+'-'+todate[0];
        url = '<?php echo site_url('archive/filter');?>?page=1&numrow='+numrow+"&fromdate="+fromdate+"&todate="+todate;
        var success = function(data)
        {
        	$('#campaigndiv').html(data);
        	$('#loading').hide();
        };
    	$('#loading').show();
        getAjax(url,"",'', '', '', false, success);
    }
    function next_page()
    {
        if(<?php echo $page?> >= <?php echo $totalpage?>)
        {
            //alert('adfa');
            $('#next').unbind('click');
            //var page =<?php echo $totalpage;?>;
        }else{
            var page = <?php echo $page?>+1; 
        }
        var numrow = $('#pagesize').val();
        
        var temp = $('#date').val();
        temp=temp.split(' <?php echo $archive_lang['to']?> ');
     	var fromdate=temp[0];
     	var todate=temp[1];
        fromdate=fromdate.split('/');
        fromdate=fromdate[2]+'-'+fromdate[1]+'-'+fromdate[0];
        todate=todate.split('/');
        todate=todate[2]+'-'+todate[1]+'-'+todate[0];
        url = '<?php echo site_url('archive/filter');?>?page='+page+'&numrow='+numrow+"&fromdate="+fromdate+"&todate="+todate;
        var success = function(data)
        {
        	$('#campaigndiv').html(data);
        	$('#loading').hide();
        };
    	$('#loading').show();
        getAjax(url,"",'', '', '', false, success);
    }
    function prev_page()
    {
        if(<?php echo $page?>==1)
        {
            $('#prev').unbind('click');
            //var page =1;
        }else{
            var page = <?php echo $page?>-1; 
        }
        var numrow = $('#pagesize').val();
        
        var temp = $('#date').val();
        temp=temp.split(' <?php echo $archive_lang['to']?> ');
     	var fromdate=temp[0];
     	var todate=temp[1];
     	fromdate=fromdate.split('/');
        fromdate=fromdate[2]+'-'+fromdate[1]+'-'+fromdate[0];
        todate=todate.split('/');
        todate=todate[2]+'-'+todate[1]+'-'+todate[0];
        url = '<?php echo site_url('archive/filter');?>?page='+page+'&numrow='+numrow+"&fromdate="+fromdate+"&todate="+todate;
        var success = function(data)
        {
        	$('#campaigndiv').html(data);
        	$('#loading').hide();
        };
    	$('#loading').show();
        getAjax(url,"",'', '', '', false, success);
    }
    $('#date').DatePicker({
        format: 'd/m/Y',
        date: ['<?php echo date('d/m/Y',strtotime($fromdate));?>','<?php echo date('d/m/Y',strtotime($todate));?>'],
        current: '<?php echo date('d/m/Y');?>',
        calendars: 2,
        mode: 'range',
        starts: 1,
        locate:'week',
        onChange: function(formated, dates) 
        {
            $('#loading').show();
            $('#date').val(formated.join(' <?php echo $archive_lang['to'];?> '));
            $('#date').DatePickerHide();
            var status = $('#status').val();
            var arrTime = formated.toString().split(',');
            var fromdate = arrTime[0];
            var todate = arrTime[1];
            fromdate=fromdate.split('/');
            fromdate=fromdate[2]+'-'+fromdate[1]+'-'+fromdate[0];
            todate=todate.split('/');
            todate=todate[2]+'-'+todate[1]+'-'+todate[0];
            var strURL="<?php echo site_url('archive/filter?');?>fromdate="+fromdate+"&todate="+todate;
            var success = function(data)
            {
            	$('#campaigndiv').html(data);
            	$('#loading').hide();
            };
        	
            getAjax(strURL,"",'', '', '', false, success);
        }
    });
    function ajax_tooltip(val,e,index,status)
    {
        if(status== -1)
        {
            $('#preview-tooltip').hide();
        }
        index-=1;
        var strURL="<?php echo site_url('banner/load_tooltip?bannerid=');?>"+val+"&index="+index+"&status="+status;
        var strId= '#tooltip';
        var strId2='#content';
        tooltip_preview (e,strId);
        $('#preview-tooltip').attr('href','<?php echo site_url('home/editAd')?>/'+val);
        var success = function(data)
        {
            $(strId2).html(data);
            tooltip_preview (e,strId);
            $('#copyad-tooltip').attr('href','<?php echo site_url('archive/deleteAd')?>/'+val);
        };
        getAjax(strURL,"",'', '', '', false, success);
    }
    
    function tooltip_preview_remove1()
    {
        tooltip_preview_remove('.ttip-ad-preview');
        $('#content').html('<div style="width: 496px;height:273px;text-align: center;"><img src="images/ajax-loader.gif" style="margin-top: 80px;"/></div>');
    }
    
    <?php if(count($info)>0){ ?>
	$(function() {        
	  $(".edit3").editable('',{ 
	    data   : "{'4':'<?php echo $archive_lang['restore'];?>'}",
	    type:"select",
	    submit : 'OK',
	    indicator : 'Wait...',
	    id : 'hk',
	    name : 'ns',
        typeEdit:true,
	    css : 'inherit',
	    cssclass : "editable",
	    onblur    : "cancel"
	  });  
	});
    <?php } ?>
    $(function() {
        $("#pdf")
            .mouseover(function() { 
                document.getElementById("pdf").src = "/images/pdf_hover.gif";
            })
            .mouseout(function() {
                document.getElementById("pdf").src = "/images/pdf.gif";
            });
        $("#excel")
            .mouseover(function() { 
                document.getElementById("excel").src = "/images/excel_hover.gif";
            })
            .mouseout(function() {
                document.getElementById("excel").src = "/images/excel.gif";
            });
        $("#top")
            .mouseover(function() { 
                document.getElementById("top").src = "/images/top.gif";
            })
            .mouseout(function() {
                document.getElementById("top").src = "/images/backtotop.gif";
            });
        $(".next")
            .mouseover(function() { 
                document.getElementById("next").src = "/images/imgnext_hover.gif";
            })
            .mouseout(function() {
                document.getElementById("next").src = "/images/imgnext.gif";   
            });
        $(".prev")
            .mouseover(function() { 
                document.getElementById("prev").src = "/images/imgpre_hover.gif";
            })
            .mouseout(function() {
                document.getElementById("prev").src = "/images/imgpre.gif";
            });
    });
</script>